package com.xqb.modules.controller.study;

import com.xqb.common.annotation.Log;
import com.xqb.common.core.controller.BaseController;
import com.xqb.common.core.domain.AjaxResult;
import com.xqb.common.core.page.TableDataInfo;
import com.xqb.common.enums.BusinessType;
import com.xqb.common.utils.poi.ExcelUtil;
import com.xqb.modules.domain.po.StdLearningLesson;
import com.xqb.modules.service.IStdLearningLessonService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学生课程Controller
 * 
 * @author xqb
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/study/learning_lesson")
public class StdLearningLessonController extends BaseController
{
    @Autowired
    private IStdLearningLessonService stdLearningLessonService;

    /**
     * 查询学生课程列表
     */
    @PreAuthorize("@ss.hasPermi('study:learning_lesson:list')")
    @GetMapping("/list")
    public TableDataInfo list(StdLearningLesson stdLearningLesson)
    {
        startPage();
        List<StdLearningLesson> list = stdLearningLessonService.selectStdLearningLessonList(stdLearningLesson);
        return getDataTable(list);
    }

    /**
     * 导出学生课程列表
     */
    @PreAuthorize("@ss.hasPermi('study:learning_lesson:export')")
    @Log(title = "学生课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StdLearningLesson stdLearningLesson)
    {
        List<StdLearningLesson> list = stdLearningLessonService.selectStdLearningLessonList(stdLearningLesson);
        ExcelUtil<StdLearningLesson> util = new ExcelUtil<StdLearningLesson>(StdLearningLesson.class);
        util.exportExcel(response, list, "学生课程数据");
    }

    /**
     * 获取学生课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:learning_lesson:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stdLearningLessonService.selectStdLearningLessonById(id));
    }

    /**
     * 新增学生课程
     */
    @PreAuthorize("@ss.hasPermi('study:learning_lesson:add')")
    @Log(title = "学生课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StdLearningLesson stdLearningLesson)
    {
        return toAjax(stdLearningLessonService.insertStdLearningLesson(stdLearningLesson));
    }

    /**
     * 修改学生课程
     */
    @PreAuthorize("@ss.hasPermi('study:learning_lesson:edit')")
    @Log(title = "学生课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StdLearningLesson stdLearningLesson)
    {
        return toAjax(stdLearningLessonService.updateStdLearningLesson(stdLearningLesson));
    }

    /**
     * 删除学生课程
     */
    @PreAuthorize("@ss.hasPermi('study:learning_lesson:remove')")
    @Log(title = "学生课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stdLearningLessonService.deleteStdLearningLessonByIds(ids));
    }
    /**
     * 获取学生最新学习课程及小节
     */
    @ApiOperation("获取学生最新学习课程及小节")
    @PreAuthorize("@ss.hasPermi('study:lesson:query')")
    @GetMapping(value = "/lastLearn")
    public AjaxResult getLastLearnInfo()
    {
        return success(stdLearningLessonService.selectLastLearnInfo());
    }

}
